import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
import { store, key } from './store/index'
import '@/assets/style/reset.css'
import '@/router/permission'
const app = createApp(App)

// 全局使用element
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/assets/style/_element.css'
import zhLocale from 'element-plus/es/locale/lang/zh-CN' // 引入Element UI的中文包
import enLocale from 'element-plus/lib/locale/lang/en' // 引入Element UI的英文包

// 使用svg图标
import 'virtual:svg-icons-register'
import Svg from '@/components/Svg.vue'
app.component('z-svg', Svg)

// 全局挂载自定义组件
import components from '@/components'
components(app)

// 全局挂载自定义指令
import directives from '@/utils/directives'
directives(app)

// 全局挂载pinia实例(registerStore全局注册，避免每次实例化后重复打包问题)
import { createPinia } from 'pinia'
import piniaPluginPersist from 'pinia-plugin-persist'
import { registerStore } from '@/stores'
const stores = createPinia()
stores.use(piniaPluginPersist)
app.use(stores)
registerStore()

// 国际化
import i18nInit from '@/i18n'
const i18n = i18nInit({ zhLocale, enLocale })

// 开发环境下使用mock
import { mockXHR } from './apiMock/index'
if (import.meta.env.MODE === 'dev') {
  mockXHR()
}

app.use(router).use(store, key).use(ElementPlus, { locale: zhLocale, size: 'default', zIndex: 5 }).use(i18n).mount('#app')
